<?php
/**
* @version 1.0.0
* @package RSSearch! 1.0.0
* @copyright (C) 2011 www.rsjoomla.com
* @license GPL, http://www.gnu.org/copyleft/gpl.html
*/
defined('_JEXEC') or die('Restricted access');
class JElementComponents extends JElement
{
	var $_name = 'Components';

	function fetchElement($name, $value, &$node, $control_name)
	{
		$components = array();
		jimport('joomla.plugin.helper');
		$plugins = JPluginHelper::getPlugin('rssearch');

		foreach($plugins as $plugin){
			$components[$plugin->name] = $plugin->name;
		}
			$result = '';
			foreach( $components as $component => $component_name) {
			if(is_array( $value) ) {
				if( in_array( $component, $value ) ) {
					$result .= '<label><input checked="checked" type="checkbox" name="'.$control_name.'['.$name.'][]" value="'.$component.'" /> '.$component_name.'</label>';
				} else {
					$result .= '<label><input type="checkbox" name="'.$control_name.'['.$name.'][]" value="'.$component.'" /> '.$component_name.'</label>';
				}
			} elseif ( $value ) {
				if( $value == $component) {
					$result .= '<label><input checked="checked" type="checkbox" name="'.$control_name.'['.$name.'][]" value="'.$component.'" /> '.$component_name.'</label>';
				} else {
					$result .= '<label><input type="checkbox" name="'.$control_name.'['.$name.'][]" value="'.$component.'" /> '.$component_name.'</label>';
				}
			} elseif ( !( $value ) ) {
					$result .= '<label><input type="checkbox" name="'.$control_name.'['.$name.'][]" value="'.$component.'" /> '.$component_name.'</label>';
			}
		}
		return $result;
	}
}
?>